package com.dajinling.socket.controller;

import com.dajinling.socket.server.WebSocketServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class SocketController {

    @Autowired
    WebSocketServer webSocketServer;

    @GetMapping("/websocket")
    public ModelAndView socket() {
        ModelAndView mav = new ModelAndView("websocket");
        return mav;
    }

    @RequestMapping(value = "/websocket/sendAll/{message}",method = RequestMethod.GET)
    @ResponseBody
    public String sendAll(@PathVariable String message){
        webSocketServer.sendAll("这是群发消息：" + message);
        return "完成";
    }
}
